#include<stdio.h>

int main()
{
	int n,flag,sign,sum=0;
	scanf("%d",&n);
	int t=n;
	while(t>9)
	{
		sum=0;
		n=t;
		while(n>0)
		{
			sum+=n%10;
			n/=10;
		}
		t=sum;
	}
	printf("%d",t);
	return 0;
}
